import Vue from 'vue'
import moment from 'moment'

Vue.filter('phoneHide', function (value) {
  return value.substr(0,7) + "****";
})


Vue.filter('num', function (value) {
  var dddd = new Array();
  dddd[0] = "这是0"
  dddd[1] = "这是1"
  dddd[2] = "这是2"
  dddd[3] = "这是3"
  return dddd[value]
})
Vue.filter('time', function (data, formatString) {
  formatString = formatString || 'YYYY-MM-DD hh:mm:ss'
  return moment(data).format(formatString)
})
Vue.filter('date', function (data, formatString) {
  formatString = formatString || 'YYYY-MM-DD';
  data = data || new Date();
  return moment(data).format(formatString)
})
Vue.filter('date1',function (data) {
  data = data || "";
  console.log(data)
  data = data.substring(0,4)+"年"+data.substring(4,6)+"月"+data.substring(6,8)+"日"
  return data;

})
Vue.filter('changeHTML', function (data1) {
  if (data1) {
    data1 = data1.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&").replace(/quot;/g, '"').replace(/&#40;/g, '(').replace(/&#41;/g, ')')
  }
  return data1;
})
Vue.filter('fileSize',function(value){
    if(null==value||value==''){
      return "0 Bytes";
    }
    var unitArr = new Array("Bytes","KB","MB","GB","TB","PB","EB","ZB","YB");
    var index=0;
    var srcsize = parseFloat(value);
    index=Math.floor(Math.log(srcsize)/Math.log(1024));
    var size =srcsize/Math.pow(1024,index);
    size=size.toFixed(2);//保留的小数位数
    return size+unitArr[index];
})


Vue.filter('formatDatetwo', function (time) {
  if(time) {
    var re = /-?\d+/;
    var m = re.exec(time);
    var d = new Date(parseInt(m[0]));
    var o = {
      "M+": d.getMonth() + 1, //month
      "d+": d.getDate(),    //day
      "h+": d.getHours(),   //hour
      "m+": d.getMinutes(), //minute
      "s+": d.getSeconds(), //second
      "q+": Math.floor((d.getMonth() + 3) / 3),  //quarter
      "S": d.getMilliseconds() //millisecond
    }
    var format = "yyyy-MM-dd";
    if (/(y+)/.test(format)) {
      format = format.replace(RegExp.$1, (d.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
      if (new RegExp("(" + k + ")").test(format)) {
        format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
      }
    }
    return format;
  }
})

window.changeHTMLFlt = function (data1) {
  // var data2 = "";
  if (data1) {
    data1 = data1.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&nbsp;/g, " ").replace(/&amp;/g, "&").replace(/quot;/g, '"').replace(/&#40;/g, '(').replace(/&#41;/g, ')')
  }
  // console.log(1111111111111)
  // console.log(data1);
  return data1;
}
